package spring.boot.fusion.mongo.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SuppressWarnings("rawtypes")
public class MongodbController {

	@Autowired
	private MongoTemplate mongoTemplate;

	@GetMapping("test")
	@SuppressWarnings("deprecation")
	public Object test() {
		for (int i = 0; i < 500; i++) {
			Map<String, Object> hashMap = new HashMap<String, Object>();
			hashMap.put("time", new Date().toLocaleString());
			hashMap.put("nickname", "BoBo" + i);
			mongoTemplate.insert(hashMap, "zxy");
		}
		return UUID.randomUUID().toString();
	}

	@GetMapping("test2")
	public Object test2() {
		List<Map> findAll = mongoTemplate.findAll(Map.class, "zxy");
		return findAll;
	}

}
